package com.muyu.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;

import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName: ResourceUtils
 * @Author: Zirun.Xin
 * @Date: 2025/4/28 上午10:27
 * @Version: 1.0
 * @Description: 资源工具
 */
@Slf4j
@Component
public class ResourceUtils {

    /**
     * 实现方式1
     */
    public void fun1() {
        String path = ClassUtils.getDefaultClassLoader().getResource("").getPath();
        String filePath = path + "static/导出excel模板.xlsx";
        log.info("实现方式1获取路径为：{}", filePath);
    }

    /**
     * 实现方式2
     * 直接获取，无需配置静态目录
     */
    public void fun2() {
        ClassPathResource classPathResource = new ClassPathResource("static/导出excel模板.xlsx");
        InputStream inputStream = null;
        try {
            inputStream = classPathResource.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        log.info("读取文件输入流信息为：{}", inputStream);
    }
}
